//#include <stdio.h>
//#include <stdlib.h>
//
//#define ERROR NULL
//typedef int ElementType;
//typedef struct LNode *PtrToLNode;
//struct LNode {
//    ElementType Data;
//    PtrToLNode Next;
//};
//typedef PtrToLNode Position;
//typedef PtrToLNode List;
//
//Position Find( List L, ElementType X );
//List Insert( List L, ElementType X, Position P );
//List Delete( List L, Position P );
//
//int main()
//{
//    List L;
//    ElementType X;
//    Position P, tmp;
//    int N;
//
//    L = NULL;
//    scanf("%d", &N);
//    while ( N-- ) {
//        scanf("%d", &X);
//        L = Insert(L, X, L);
//        if ( L==ERROR ) printf("Wrong Answer\n");
//    }
//    scanf("%d", &N);
//    while ( N-- ) {
//        scanf("%d", &X);
//        P = Find(L, X);
//        if ( P == ERROR )
//            printf("Finding Error: %d is not in.\n", X);
//        else {
//            L = Delete(L, P);
//            printf("%d is found and deleted.\n", X);
//            if ( L==ERROR )
//                printf("Wrong Answer or Empty List.\n");
//        }
//    }
//    L = Insert(L, X, NULL);
//    if ( L==ERROR ) printf("Wrong Answer\n");
//    else
//        printf("%d is inserted as second last element.\n", X);
//    P = (Position)malloc(sizeof(struct LNode));
//    tmp = Insert(L, X, P);
//    if ( tmp!=ERROR ) printf("Wrong Answer\n");
//    tmp = Delete(L, P);
//    if ( tmp!=ERROR ) printf("Wrong Answer\n");
//    for ( P=L; P; P = P->Next ) printf("%d ", P->Data);
//    return 0;
//}
//
///* 你的代码将被嵌在这里 */
//Position Find(List L, ElementType X) {
//    while (L != NULL) {
//        if (L->Data == X) {
//            return L;
//        }
//        L = L->Next;
//    }
//    return ERROR;
//}
//List Insert( List L, ElementType X, Position P ){
//    int length = 0;
//    while(L != NULL){
//        length++;
//        L = L->Next;
//    }
//    if(P<1||P>length+1){
//        printf("Wrong Position for Insertion");
//        return ERROR;
//    }
//    for(int i=length;i>=P;i--){
//        L->Data = L->Next->Data;
//        L = L->Next;
//    }
//    for(int i=0;i<P;i++){
//        if(i==P-1){
//            L->Data = X;
//        }
//        L = L->Next;
//    }
//    return L;
//}
//List Delete( List L, Position P ){
//    int length = 0;
//    while(L != NULL){
//        length++;
//        L = L->Next;
//    }
//    if(P<1||P>length+1){
//        printf("Wrong Position for Deletion");
//        return ERROR;
//    }
//    for(int i=0;i<length;i++){
//        if(i==P-2){
//            L->Next = L->Next->Next;
//        }
//        L = L->Next;
//    }
//    return L;
//}
#include <stdio.h>
#include <stdlib.h>

#define ERROR NULL
typedef int ElementType;
typedef struct LNode *PtrToLNode;
struct LNode {
    ElementType Data;
    PtrToLNode Next;
};
typedef PtrToLNode Position;
typedef PtrToLNode List;

Position Find( List L, ElementType X );
List Insert( List L, ElementType X, Position P );
List Delete( List L, Position P );

int main()
{
    List L;
    ElementType X;
    Position P, tmp;
    int N;

    L = NULL;
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        L = Insert(L, X, L);
        if ( L==ERROR ) printf("Wrong Answer\n");
    }
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        P = Find(L, X);
        if ( P == ERROR )
            printf("Finding Error: %d is not in.\n", X);
        else {
            L = Delete(L, P);
            printf("%d is found and deleted.\n", X);
            if ( L==ERROR )
                printf("Wrong Answer or Empty List.\n");
        }
    }
    L = Insert(L, X, NULL);
    if ( L==ERROR ) printf("Wrong Answer\n");
    else
        printf("%d is inserted as the last element.\n", X);
    P = (Position)malloc(sizeof(struct LNode));
    tmp = Insert(L, X, P);
    if ( tmp!=ERROR ) printf("Wrong Answer\n");
    tmp = Delete(L, P);
    if ( tmp!=ERROR ) printf("Wrong Answer\n");
    for ( P=L; P; P = P->Next ) printf("%d ", P->Data);
    return 0;
}

/* 你的代码将被嵌在这里 */
Position Find(List L, ElementType X) {
    Position P = L;  // 从头节点开始
    while (P) {
        if (P->Data == X) {
            return P;
        }
        P = P->Next;
    }
    return ERROR;  // 没找到时返回ERROR
}
List Insert(List L, ElementType X, Position P) {
    // 创建新节点
    Position newNode = (Position)malloc(sizeof(struct LNode));
    if (newNode == NULL) {
        return ERROR;  // 内存分配失败
    }
    newNode->Data = X;
    
    // 特殊情况：空链表且P为NULL（插入到末尾）
    if (L == NULL && P == NULL) {
        newNode->Next = NULL;
        return newNode;
    }
    
    // 特殊情况：插入到链表头
    if (P == L) {
        newNode->Next = L;
        return newNode;
    }
    
    // 遍历找到P的前一个节点
    Position current = L;
    Position prev = NULL;
    
    while (current != NULL && current != P) {
        prev = current;
        current = current->Next;
    }
    
    // P不在链表中（除了NULL的情况）
    if (current != P && P != NULL) {
        printf("Wrong Position for Insertion\n");
        free(newNode);
        return ERROR;
    }
    
    // 插入节点
    if (prev == NULL) {  // 在链表头插入
        newNode->Next = L;
        return newNode;
    } else {  // 在链表中间或末尾插入
        newNode->Next = current;
        prev->Next = newNode;
        return L;
    }
}
List Delete(List L, Position P) {
    if (L == NULL || P == NULL) {
        printf("Wrong Position for Deletion\n");
        return ERROR;
    }
    
    Position current = L;
    Position prev = NULL;
    
    while (current != NULL && current != P) {
        prev = current;
        current = current->Next;
    }
    
    if (current == NULL) {
        printf("Wrong Position for Deletion\n");
        return ERROR;
    }
    
    if (prev == NULL) {
        L = current->Next;
    } else {
        prev->Next = current->Next;
    }
    
    free(current);
    return L;
}

